import React, { Component } from "react";
import Child1 from "./Child1";

import { Provider } from "./cart";

class App extends Component {
  state = {
    count: 4,
  };
  add = (num) => {
    this.setState((prevState) => ({
      count: prevState.count + num,
    }));
  };
  minus = () => {
    this.setState((prevState) => ({
      count: prevState.count - 1,
    }));
  };
  render() {
    return (
      <Provider
        value={{ count: this.state.count, add: this.add, minus: this.minus }}
      >
        <h2>计数器</h2>
        <Child1 />
      </Provider>
    );
  }
}

export default App;
